home *** CD-ROM | disk | FTP | other *** search
- Path: dispatch.news.demon.net!demon!alma.ipso.net
- From: martin@ipso.net (Martin Barry)
- Newsgroups: comp.lang.c++
- Subject: Re: Q: structures&arrays
- Date: Sat, 20 Apr 1996 13:38:57 GMT
- Message-ID: <3178e5ce.169129341@news.ipso.net>
- References: <4l93s7$9ej@news.inc.net>
- Reply-To: martin@ipso.net
- NNTP-Posting-Host: alma.ipso.net
- X-NNTP-Posting-Host: alma.ipso.net
- X-Newsreader: Forte Agent .99e/32.201
-
- pendrick@it.uwp.edu (Richard Pendrick) wrote:
-
- : I would appreciate it if someone could enlighten me on why the
- below
- : program errors, and what the correct procedure is for initializing
- an
- : array of a structure.
-
- on the intialisation of structures, we may have:
- struct point
- {
- int y;
- int x;
- };
-
- and then initialise, say:
-
- struct oint maxpt = {320, 200};
-
- that's how you do it!
-
- now in your example, i must take a guess that you got mixed up,
- because you try to declare an array of type foo, but then try and make
- one element of it of type foo. i think what you wanted was to come
- out with was an array type variable.... so how about this?
-
- #include <iostream.h>
-
- struct foo
- {
- char n[30];
- int p;
- };
-
- int main(void)
- {
- struct foo f = { "rick", 1 }; //we declare and intialise
- cout << f.n << " " <<f.p; //will print this out for you
-
- return 0;
- }
-
-
-
- hope that helps
-
- llp
-
-
- baz
-
-
-